#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back

using namespace std;

typedef long long ll;
typedef double db;
typedef vector < int > vec;
typedef pair < int , int > pii;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(ch != EOF && !isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

namespace F { // max_flow
    const int N = 55;
    const int M = N * N;
    const int inf = 0x3f3f3f3f;
    int h[N],now[N],d[N],cnt = 1,S,T;
    struct edge { int v,w,nxt; } e[M << 1];
    inline void tlink(int x,int y,int w) { e[++cnt] = (edge) { y,w,h[x] }; h[x] = cnt; }
    inline void link(int x,int y,int w) { tlink(x,y,w); tlink(y,x,0); }
    inline void setst(int s,int t) { S = s; T = t; }
    void reset() { cnt = 1; memset(h,0,sizeof h); }
    queue < int > q;
    bool bfs() {
	while(q.size()) q.pop(); q.push(S); memset(d,0,sizeof d); d[S] = 1; now[S] = h[S];
	while(!q.empty()) {
	    int x = q.front(); q.pop();
	    for(int i = h[x],y;i;i = e[i].nxt)
		if(e[i].w && !d[y = e[i].v]) {
		    d[y] = d[x] + 1; q.push(y); now[y] = h[y];
		    if(y == T) return 1;
		}
	} return 0;
    }
    int dinic(int x,int flow) {
	if(x == T) return flow;
	int res = flow;
	for(int i = now[x],y;i && res;i = e[i].nxt) {
	    now[x] = i;
	    if(e[i].w && d[y = e[i].v] == d[x] + 1) {
		int k = dinic(y,min(res,e[i].w));
		if(!k) d[y] = 0; e[i].w -= k; e[i ^ 1].w += k; res -= k;
	    }
	}
	return flow - res;
    }
    ll runit() {
	ll maxflow = 0,flow;
	while(bfs()) while(flow = dinic(S,inf)) maxflow += flow;
	return maxflow;
    }
};

const int N = 55;

int n,m;
char s[N][N];

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
    while(n = in) {
	int a1 = in + 1,a2 = in + 1,an = in,b1 = in + 1,b2 = in + 1,bn = in;
	F :: reset();
	for(int i = 1;i <= n;i++) scanf("%s",s[i] + 1);
	for(int i = 1;i <= n;i++)
	    for(int j = 1;j <= n;j++)
		if(s[i][j] == 'O') F :: link(i,j,2);
		else if(s[i][j] == 'N') F :: link(i,j,F :: inf);
	F :: setst(0,n + 1); F :: link(0,a1,an * 2); F :: link(a2,n + 1,an * 2);
	F :: link(0,b1,bn * 2); F :: link(b2,n + 1,bn * 2);
	//	cerr << F :: runit() <<endl; continue;
	if(F :: runit() != 2 * (an + bn)) { puts("No"); continue; }
	F :: reset();
	for(int i = 1;i <= n;i++)
	    for(int j = 1;j <= n;j++)
		if(s[i][j] == 'O') F :: link(i,j,2);
		else if(s[i][j] == 'N') F :: link(i,j,F :: inf);
	F :: setst(0,n + 1); F :: link(0,a1,an * 2); F :: link(a2,n + 1,an * 2);
	F :: link(0,b2,bn * 2); F :: link(b1,n + 1,bn * 2);
	if(F :: runit() != 2 * (an + bn)) { puts("No"); continue; }
	puts("Yes");
    }
    return 0;
}
